#include <iostream>
#include <cmath>
using std::cout;
using std::cin;
using std::endl;
using std::string;
class Figure {
public:
    virtual string getName() const = 0;
    virtual double getArea() const = 0;
};

void display(Figure& fig) {
    cout << fig.getName()
        << "的面积是:"
        << fig.getArea() << endl;
}

class Rectangle
    :public Figure
{
public:
    Rectangle(double l, double w)
        :m_l(l)
        , m_w(w)
    {
    }
    virtual string getName() const override {
        return string("Rectangle");
    }
    virtual double getArea() const {
        return m_w * m_l;
    }
private:
    double m_l;
    double m_w;
};

class Circle
    :public Figure
{
public:
    Circle(double r)
        :m_r(r)
    {
    }
    virtual string getName() const override {
        return string("Circle");
    }
    virtual double getArea() const {
        return m_r * m_r * 3.14;
    }
private:
    double m_r;
};

class Triangle
    :public Figure
{
public:
    Triangle(double edg1, double edg2, double edg3)
        :m_edg1(edg1)
        , m_edg2(edg2)
        , m_edg3(edg3)
    {
    }
    virtual string getName() const override {
        return string("Triangle");
    }
    virtual double getArea() const override {
        double s = (m_edg1 + m_edg2 + m_edg3) / 2;

        return std::sqrt(s * (s - m_edg1) * (s - m_edg2) * (s - m_edg3));
    }
private:
    double m_edg1;
    double m_edg2;
    double m_edg3;
};
void test() {
    Rectangle r(10, 20);
    Circle c(15);
    Triangle t(3, 4, 5);
    display(r);
    display(c);
    display(t);
}
int main() {
    test();
    return 0;
}